<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String rightPage = (String) request.getAttribute("rightPage");
%>
<!DOCTYPE HTML>
<html>
<head>
<c:set var="title" value="地址管理" scope="request" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link href="shop/css/shop-top.css" rel="stylesheet" />
<link href="shop/css/shop-detail.css" rel="stylesheet" />
<link href="shop/css/shop-footer.css" rel="stylesheet" />
<link href="shop/css/shop-tuan.css" rel="stylesheet" />
<link href="shop/css/shop-common.css" rel="stylesheet" />

<jsp:include page="/head.jsp" />
<script type="text/javascript" src="shop/js/shop-/public.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="shop/js/shop-layer.js"></script>
<script type="text/javascript" src="/shop/js/shop-jquery-1.5.1.js"></script>
</head>

<body>

    <c:import url="/news-class.do?mb=header" /> 
	<%@ include file="jsps/top.jsp"%>
	<div class="yershop_wrapper">
		<%@ include file="jsps/hader.jsp"%>
		<div class="menu-wrapper">
			<div class="nava">
				<div class="nav-all">
				</div>
				<ul class="menu">
					<li><a href="shop.html" target="_self">首页</a></li>
					<li><a href="shop.html" target="_blank">团购</a></li>
					<li><a href="shop.html" target="_self">抢购</a></li>
					<li><a href="shop.html" target="_self">预约</a></li>
				</ul>
			</div>
		</div>
		<!-- /菜单 -->

		<!-- 主体 -->
		<div class="commom_wrapper">

			<div class="main">
				<div class="main_center">
					<div class="center_left">
						<!-- 左侧菜单 -->
						<h3>
							<a rel="nofollow" href="javascript:vod(0)" class="home-me">我的会员中心</a>
						</h3>
						<dl>
							<dd>
								<%-- <a rel="nofollow" href="userMain.page"
									<c:if test="${rightPage=='orderAll' || rightPage=='orderDetail' }">class="current"</c:if>>我的订单</a> --%>
								<!-- <a rel="nofollow"  href="order.jsp" <c:import url="order.do"></c:import>>我的订单</a> -->
								<a rel="nofollow" href="sss-1.do">我的订单</a>
							</dd>
						</dl>

						<dl class="last">
							<dd>
								<%-- <a rel="nofollow" href="userAddress.page"
									<c:if test="${rightPage=='address' || rightPage=='addAddress' }">class="current"</c:if>>地址管理</a> --%>
								<a rel="nofollow" href="userAddress.page" class="current">地址管理</a>
							</dd>
							<dd>
								<a rel="nofollow" href="index.cart">我的购物车</a>
							</dd>
						</dl>

						<script>
							/* 左边菜单高亮 */
							url = window.location.pathname
									+ window.location.search;
							url = url
									.replace(
											/(\/(p)\/\d+)|(&p=\d+)|(\/(id)\/\d+)|(&id=\d+)|(\/(group)\/\d+)|(&group=\d+)/,
											"");

							$("a[href='" + url + "']").addClass("current");
						</script>

						<!-- 左侧菜单 -->

					</div>

					<%-- <%@include file="jsps/userMain/address.jsp"%> --%>

					<!-- 地址管理 -->
					<div class="center_right" style="display: block;">
						<div class="red"
							style="clear: both; overflow: hidden; padding: 10px;">收货地址管理（选中表示为默认）</div>
						<!-- <form method="post" class="person-add" name="form" action="address.do"> -->
							<!-- 提交表单到address.do -->
							<ul style="margin-left: 40px;" class="list">
								<c:forEach items="${addresslist }" var="address">
									<p>
										<c:if test="${address.shopAddressMsg==1 }">
											<input type="radio" checked="checked"
												id="d ${address.shopAddressId  }" name="sender"
												value="${address.shopAddressId  }" />&nbsp;收件人：${address.shopAddressRealName }&nbsp;&nbsp;联系电话:${address.shopAddressUserTel }&nbsp;&nbsp;收货地址：${address.shopAddressProvince }${address.shopAddressCity }${address.shopAddressArea }${address.shopAddressUserAddress} 
       									</c:if>
										<c:if test="${address.shopAddressMsg!=1 }">
											<input type="radio" id="d" name="sender"
												value="${address.shopAddressId  }" />&nbsp;收件人：${address.shopAddressRealName }&nbsp;&nbsp;联系电话:${address.shopAddressUserTel }&nbsp;&nbsp;收货地址：${address.shopAddressProvince }${address.shopAddressCity }${address.shopAddressArea }${address.shopAddressUserAddress} 
      								 	</c:if>
									</p>
								</c:forEach>
								<%-- <c:forEach items="${addresslist }" var="address">
									<li id="d ${address.shopAddressId }"><span>
									<input type="radio" name="id" value="${address.shopAddressId } " checked="checked"
											<c:if test="${address.shopAddressMsg==1 }">checked="checked"</c:if>></span>
										${address.shopAddressProvince } ${address.shopAddressCity }
										${address.shopAddressArea }${address.shopAddressUserAddress }
										收货人：${address.shopAddressRealName }
										手机号：${address.shopAddressUserTel }</li>
								</c:forEach> --%>
								<li>
								    <!-- <input type="button"  class="btn-xiugai redd" value="设置默认"  onclick="shezhi();return false;" >&nbsp; -->
								    <a class="btn-xiugai redd" onclick="shezhi();return false;" href="userAddress.page">设置默认</a>&nbsp;
									<!-- <input type="button" class="btn-xiugai blue" value="删除" onclick="del();">&nbsp; -->
									<a class="btn-xiugai blue" onclick="shanchu();return false;" href="userAddress.page">删除</a>&nbsp; 
									<%-- <a class="btn-xiugai blue" onclick="cancelDel(${address.shopAddressId});return false;"  href="">删除</a>&nbsp; --%>
									<a href="addAddress.page" class="btn-xiugai orange">增加</a>
									<!-- <a onclick="fresh();return false;" class="btn-xiugai orange">刷新</a> -->
								</li>
								<br>
							</ul>
						<!-- </form> -->
						<script type="text/javascript">
							function del() {
								var cartItemIdArray = $('input:radio[name="sender"][checked=true]').val();//获取地址编号
								$("#asd").val(cartItemIdArray);
							}

							//设置默认
							function shezhi() {
								/* var val = $('input:radio[name="id"]:checked').val(); */
								var val = $('input:radio[name="sender"][checked=true]').val();
								//判断新地址是否选中,获取地址id
								if (val == null) {
									alert("请选择一个地址!");
									return false;
								} else if (window.confirm('你确定要设置为默认地址吗？')) {
									$
											.ajax({
												type : 'post', //传送的方式,get/post
												url : 'setDefault.address', //发送数据的地址
												data : {
													id : val
												},
												dataType : "json",
												 /* success : function(data) {
													if (data.success) {
														layer.alert("设置成功！", {
															icon : 1
														});
													} else {
														layer.alert("设置失败！", {
															icon : 2
														});
													}
												},
												error : function(event, XMLHttpRequest, ajaxOptions, thrownError) {
													alert(XMLHttpRequest + thrownError);
												} */
											});
									/* fresh(); */
								}
							}
							
							//删除地址
							function shanchu() {
								/* var val = $('input:radio[name="id"]:checked').val(); */
								var val = $(
										'input:radio[name="sender"][checked=true]')
										.val();
								/* var val =  $('input:radio[name="id"][checked=true]').val(); */
								//判断新地址是否选中,获取地址id
								if (val == null) {
									alert("请选择一个地址!");
									return false;
								} else if (window.confirm('你确定要删除吗？')) {
									$.ajax({
										type : "post", //传送的方式,get/post
										url : "delete.address", //发送数据的地址
										data : {
											id : val
										},
										dataType : "json",
										success : function(data) {
											if (data.success) {
												$('#d' + val).remove();
												/* 	layer.alert("已删除该条地址！", { icon : 1 }, 	function(index) {
																		//do something
																		layer.close(index);
																		window.location.href = "/userAddress.page";
																		// window.refresh();
																		// location.replace(location);
																	}); */
											}
										}
									});
									fresh();
								}
							}

							/* function fresh() {
								parent.location.replace(parent.location.href);//服务器端重新创建页面
								parent.document.location.reload();//相当于F5
								window.location.href(parent.location.href);//iframe内容重定向
							} */
							
							function fresh() {
								location.reload();
							}
						</script>
						<!-- 个人中心 初始状态 end -->
					</div>

				</div>
			</div>
			<!-- 主体 -->

			<!-- 购物车js -->
			<script>
				//购物车显示与隐藏
				var Shopcart = document.getElementById('shopping_cart');
				var Goodsmenu = document.getElementById('goods');
				var timerr = null;//定义定时器变量
				//鼠标移入div1或div2都把定时器关闭了，不让他消失
				Shopcart.onmouseover = Goodsmenu.onmouseover = function() {
					Goodsmenu.style.display = 'block';
					clearTimeout(timerr);
				}
				//鼠标移出div1或div2都重新开定时器，让他延时消失
				Shopcart.onmouseout = Goodsmenu.onmouseout = function() {
					//开定时器
					timerr = setTimeout(function() {
						Goodsmenu.style.display = 'none';
					}, 10);
				}

				//购物车动态删除
				function delcommon(event) { //获取事件源
					event = event ? event : window.event;
					var obj = event.srcElement ? event.srcElement
							: event.target;
					//这时obj就是触发事件的对象，可以使用它的各个属性 
					//还可以将obj转换成jquery对象，方便选用其他元素 
					str = obj.innerHTML.replace(/<\/?[^>]*>/g, ''); //去除HTML tag

					var $obj = $(obj);
					var str = $obj.parent().prev().html();
					if (obj.rel == "del") {
						var str = obj.name;
						var uexist = "";
						//全选的实现 定义删的发送路径
						if (uexist) {
							var del = '/index.php?s=/Home/Shopcart/delItemByuid.html';
						} else {
							var del = 'delShoppingCart.goods';

						}

						$
								.ajax({
									type : 'post', //传送的方式,get/post
									url : del, //发送数据的地址
									data : {
										sort : str
									},
									dataType : "json",
									success : function(data) {
										var $obj = $(obj);
										$obj.parents("li").remove();
										if (data.sum == "0") { //判断购物车数量是否为0，为0则隐藏底部查看工具
											$("div.sc_goods_foot").hide();
											var html = '<p class="sc_goods_none" >您的购物车还是空的，赶紧行动吧！</p>';
											$("ul.sc_goods_ul").html(html);

										} else {
											$("div.sc_goods_foot").show();
										}

									},
									error : function(event, XMLHttpRequest,
											ajaxOptions, thrownError) {
										alert(XMLHttpRequest + thrownError);
									}
								})
					}

				}
				//购物车删除结束
			</script>
			<!-- /购物车js -->

			<!-- 底部 -->

			<!-- 底部-->
			<script type="text/javascript" charset="utf-8"
				src="shop/js/shop-menudown.js"></script>

		</div>
	</div>
	<%@ include file="jsps/footer.jsp"%>
	<input type="hidden" id="asd" name="cho_Area" value="" />
</body>
</html>